
package com.kedacom.ctsp.authority.dao;

import com.kedacom.ctsp.authority.entity.Department;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 部门 DAO接口
 *
 * @author sunchenjie
 */
public interface DepartmentJpaDao extends JpaRepository<Department, String> {

    /**
     * 根据id获取部门Path
     *
     * @param id
     * @return
     */
    @Query(nativeQuery = true, value = "select path from department where id= ?1")
    List getDeptPathById(String id);


    /**
     * 根据id列表获取部门Path列表
     *
     * @param ids
     * @return
     */
    @Query(nativeQuery = true, value = "select DISTINCT path from department where id in ?1")
    List getDeptPathByIds(List<String> ids);


    /**
     * 根据path模糊查询获取部门编号
     *
     * @param path
     * @return
     */
    @Query(nativeQuery = true, value = "select DISTINCT code from department where path like ?1%")
    List getDeptCodeByPathLike(String path);


    /**
     * 获取所有部门path和编号
     *
     * @return
     */
    @Query(nativeQuery = true, value = "select path,code from department ")
    List getDeptCodeAndPath();


    /**
     * 获取所有部门path
     *
     * @return
     */
    @Query(nativeQuery = true, value = "select path from department ")
    List getAllPath();


    /**
     * 根据code获取deptId
     *
     * @return
     */
    @Query(nativeQuery = true, value = "select id from department where code= ?1")
    String getDeptIdByCode(String code);

    /**
     * 根据code获取deptId
     *
     * @return
     */
    @Query(nativeQuery = true, value = "select DISTINCT id from department where code in ?1")
    List getDeptIdsByCodes(List<String> codes);
}
